/*	
 *				
 *					ISNW ---- It is a war.It is not warcraft!
 *
 *
 *					Author:					zhoukeli(haxixi_keli)
 *					Filename:				ParticleSystemSceneNode.h
 *					CreateTime:				2008/12/30
 *					ModifyTime:				2008/12/30
 *
 */

#ifndef __ISNW_PARTICLE_SYSTEM_SCENE_NODE_H__
#define __ISNW_PARTICLE_SYSTEM_SCENE_NODE_H__

#include "include/IParticleSystemSceneNode.h"
#include "include/IParticalEmitter.h"
#include "include/isnwMaterial.h"
#include "MeshBuffer.h"
#include "include/dimension2d.h"
#include "include/IParticleAffector.h"
#include "include/Particle.h"

namespace ISNW
{
namespace scene
{
	class ParticleSystemSceneNode : public IParticleSystemSceneNode
	{
	public:
		ParticleSystemSceneNode(ISceneManager* sm,ISceneNode* parent,s32 id,core::vector3df pos,
			core::vector3df rotate,core::vector3df scale,bool DefaultEmitter)
			:IParticleSystemSceneNode(sm,parent,id,pos,rotate,scale)
			,useDefaultEmitter(useDefaultEmitter)
			,emitter(0)
			,lastTime(0)
		{
			ParticleSize.set(10,10);
			if(DefaultEmitter)
			{
				core::aabbox3df box;
				box.reset(core::vector3df(-100,0,-100));
				box.addpoint(core::vector3df(100,1,100));
				IParticleEmitter* em = createBoxEmitter(box,core::vector3df(0,1,0),1000,500,0xFFFFFFFF,0xFF0000FF,360,3000);
				setEmitter(em);
			}
		}

	public:
		void setEmitter(IParticleEmitter* e);

		void render();

		void doParticleSystem(u32 Time);

		void setParticleSize(core::dimention2df size)
		{
			ParticleSize = size;
		}

		IParticleEmitter* createBoxEmitter(core::aabbox3df box,core::vector3df dir,u32 MPPS,u32 mpps,u32 MCOLOR,u32 mcolor,
			u32 angle,u32 life);

		void onRegisterSceneNode();

		virtual void addAffecor(IParticleAffector* af)
		{
			if(!af) return;

			af->grab();
			Affectors.push_back(af);
		}

		virtual void setMaterial(video::material m);


	public:
		bool useDefaultEmitter;

		IParticleEmitter*	emitter;

		MeshBuffer	buffer;

		u32 lastTime;

		core::dimention2df ParticleSize;

		core::array<Particle> Particles;

		core::list<IParticleAffector*> Affectors;
	};

} // end namespace scene
} // end namespace ISNW
#endif